package cate.game.play.skill.passive.god;

import cate.common.util.XT;
import cate.game.play.buff.Buff;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 自身负面状态大于1时，受到负面状态有概率40%将此负面状态回敬给施法者，每回合至多1次（非转移，自身负面不会消失）
 */
public class 睚眦PH extends PassiveHandler {


	private int 概率;

	//概率=4000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
	}

	private int lastRound;

	@Override
	public void onOwnerAddBuff(ActionCtx action, Buff addBuff) {
		if (addBuff.isGood()) {
			return;
		}
		if (lastRound >= action.getRound().index) {
			return;
		}
		if (skill.owner.getTeam() == addBuff.caster.getTeam()) {
			return;
		}
		if (skill.owner.buff.countBuff(b -> !b.isGood()) == 1) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		lastRound = action.getRound().index;
		addBuff.caster.buff.tryAddByTid(action, skill.owner, addBuff.tid);
	}
}
